package com.htc.callcare.viewcontroller;

import java.io.File;


import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import com.htc.callcare.R;
import com.htc.callcare.activities.RecordActivity;
import com.htc.callcare.adapter.RecordAdapter;
import com.htc.callcare.database.Database;
import com.htc.callcare.infrastructure.globalVar;
import com.htc.callcare.model.recordModel;

public class RecordController {
	RecordActivity activity;
	recordModel model;

	public RecordController(RecordActivity activity) {
		super();
		this.activity = activity;
	}

	public recordModel getModel() {
		return model;
	}

	public void setModel(recordModel model) {
		this.model = model;
	}

	public void detete(recordModel processModel, RecordAdapter adapter) {
		// TODO Auto-generated method stub
		File file=new File(globalVar.recordDir+processModel.getFileUri());
		file.delete();
		adapter.getRecords().remove(processModel);
		Toast.makeText(activity, activity.getResources().getString(R.string.delete), Toast.LENGTH_SHORT).show();
		activity.updateAdapter();
	}
	public void send(recordModel processModel){	
		Uri uri = Uri.fromFile(new File(globalVar.recordDir, processModel.getFileUri()));
		Intent it = new Intent(Intent.ACTION_SEND);   
		it.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.recordFile)+" "+  processModel.getCallNumber());   
		it.putExtra(Intent.EXTRA_TEXT, activity.getString(R.string.date)+processModel.getCallDay()+"   "+activity.getString(R.string.time)+processModel.getCallTime()); 
		it.putExtra(Intent.EXTRA_STREAM, uri);
		it.setType("audio/rfc822");   
		activity.startActivity(Intent.createChooser(it,activity.getString(R.string.share))); 
	}
	
	public void deleteItem(recordModel processModel){
		File file=new File(globalVar.recordDir+processModel.getFileUri());
		file.delete();
	}

	

}
